<?php
/**
 * Synchronize User Mailboxes
 * 
 * @author Xavier VILAIN
 * @package Orx\Mailer
 * @license #hive-mailer#
 */
$xview = Xview::instance();
$force = $xview->val('force',false);
if(!DEV_ENV) {
	set_time_limit(300);
}
$synchronizations = User::current()->synchronizeMailers($force);

if(!empty($synchronizations)) {
	// Return result of the synchronization
	foreach($synchronizations as $sync) {
		if(empty($sync)) {
			continue;
		}
		if($sync->status == Orx\User\MailBox::STATUS_ERROR) {
			\Fox\Message::Error($sync->message);
		} else {
			\Fox\Message::Success($sync->message);
		}
	}
	$json = $xview->val('json',true);
	if($json) {
		echo $xview->messages(true,true);
	}
}